package com.zh.juc.cas;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @Author: zhanghuan
 * @date: 2022/10/18 20:46
 * @description: create it
 * 原子引用
 */
@Getter
@ToString
@AllArgsConstructor
class User {
    private String name;
    private int age;
}

public class CASDemo03 {

    public static void main(String[] args) {
        AtomicReference<User> atomicReference = new AtomicReference<>();
        User zhansan = new User("zhansan", 22);
        User lisi = new User("lisi", 22);
        atomicReference.set(zhansan);
        System.out.println(atomicReference.compareAndSet(zhansan, lisi) + "\t" + atomicReference.get());
    }
}
